<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    function flatter (arr) {
        if (!arr.length) return;
        return arr.reduce(
            (pre, cur) =>
                Array.isArray(cur) ? [...pre, ...flatter(cur)] : [...pre, cur],
            []
        );
    }
    console.log(flatter([1, 2, [1, [2, 3, [4, 5, [6]]]]]));
</script>
</html>